package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.modules.generator.dao.CodeDicDao;
import io.renren.modules.generator.dao.EnterpriseMainDao;
import io.renren.modules.generator.dto.GardenPortraitCommonResult;
import io.renren.modules.generator.entity.CodeDicEntity;
import io.renren.modules.generator.entity.EnterpriseMainEntity;
import io.renren.modules.generator.service.EnterprisePortraitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author zhangxu
 * @create 2020/9/23
 * Description:
 */
@Service("enterprisePortraitService")
public class EnterprisePortraitServiceImpl implements EnterprisePortraitService {

    @Autowired
    private EnterpriseMainDao enterpriseMainDao;
    @Autowired
    private CodeDicDao codeDicDao;

    @Override
    public Map<String, Object> selectSurvey() {
        Map<String, Object> result = new HashMap<>();
        result.put("SumFrontYearProduce",enterpriseMainDao.selectSumFrontYearProduce());
        result.put("SumEnterpriseMain",enterpriseMainDao.selectCount(null));
        result.put("SumEnterpriseMember",enterpriseMainDao.selectSumEnterpriseMember());
        return result;
    }

    @Override
    public List<GardenPortraitCommonResult> selectTypeStatis() {
        List<GardenPortraitCommonResult> resultGardenPortraitCommonResultList = new ArrayList<>();
        List<GardenPortraitCommonResult> gardenPortraitCommonResultList = enterpriseMainDao.selectTypeStatis();
        gardenPortraitCommonResultList.forEach(gardenPortraitCommonResult -> {
            QueryWrapper<CodeDicEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda()
                    .eq(CodeDicEntity::getCode,gardenPortraitCommonResult.getName())
                    .eq(CodeDicEntity::getType,"enterprise_type");
            CodeDicEntity codeDicEntity = codeDicDao.selectOne(queryWrapper);
            if(Objects.nonNull(codeDicEntity)){
                gardenPortraitCommonResult.setName(codeDicEntity.getName());
                resultGardenPortraitCommonResultList.add(gardenPortraitCommonResult);
            }
        });
        return resultGardenPortraitCommonResultList;
    }


    @Override
    public List<GardenPortraitCommonResult> selectEvaluateStatis() {
        List<GardenPortraitCommonResult> gardenPortraitCommonResultList = enterpriseMainDao.selectEvaluateStatis();
        gardenPortraitCommonResultList.forEach(gardenPortraitCommonResult -> {
            QueryWrapper<CodeDicEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda()
                    .eq(CodeDicEntity::getCode,gardenPortraitCommonResult.getName())
                    .eq(CodeDicEntity::getType,"enterprise_evaluate");
            CodeDicEntity codeDicEntity = codeDicDao.selectOne(queryWrapper);
            if(Objects.nonNull(codeDicEntity)){
                gardenPortraitCommonResult.setName(codeDicEntity.getName());
            }
        });
        return gardenPortraitCommonResultList;
    }
}
